package adapter;/*
 *@创建者 lnn
 *@创建时间2016/9/10:27
 *@描述 ${TODO}
*/

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.example.administrator.boltshow.R;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;

import model.BoltHomeModel;

public class BoltBaseAdapter  extends BaseAdapter{
    private List<BoltHomeModel.DataBean> mData;
    private Context mContext;
    private ImageOptions mImageOptions;

    public BoltBaseAdapter(List<BoltHomeModel.DataBean> data,Context context) {
        mContext = context;
        mData = data;
        mImageOptions = new ImageOptions.Builder().setUseMemCache(true).build();
    }
    @Override
    public int getCount() {
        return mData==null?0:mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder holder = null;
        if(convertView==null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_holt, null);
                holder = new MyViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (MyViewHolder) convertView.getTag();
        }
        BoltHomeModel.DataBean dataBean = mData.get(position);
        x.image().bind(holder.ivShow, dataBean.getImgUrl(), mImageOptions);

        return convertView;
    }
    public static class MyViewHolder{
        private ImageView ivShow;

        public MyViewHolder(View itemView) {
            ivShow = (ImageView) itemView.findViewById(R.id.iv_item_holt_show);
        }
    }
}
